import { history } from 'umi'
import wx from 'weixin-webview-jssdk'

const messageData = [
    { path: '/job/ability', type: 'eval' },
    { path: '/job/list', type: 'eval' },
    { path: '/measurements', type: 'eval' },
    { path: '/job/exam', type: 'eval' },
    { path: '/evaluation', type: 'eval' },
    { path: '/organization/detail', type: 'company_view' },
]
/** 发送消息给小程序并重定向 */
const postMsgRedirect = (arg?: number) => {
    let data = { type: '401' }
    let url = '/pages/login/login'
    const flag = messageData.find(item => history.location.pathname.startsWith(item.path))
    if (flag) {
        const { path, ...values } = flag
        data = values
        url += `?isQzGuest=false&routerUrl=/pages/redirectPage/index&type=${values.type}&arg=${arg}`
    }
    wx.miniProgram.navigateTo({ url })
    // wx.miniProgram.postMessage({ data })
}

export default postMsgRedirect
